package com.hupeng.domain;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.hupeng.enums.OrderStatusEnum;
import com.hupeng.enums.PayStatusEnum;

import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the order_master database table.
 * 
 */
@Entity
@Data
@DynamicUpdate
public class OrderMaster implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GenericGenerator(name="idGenerator", strategy="uuid") //这个是hibernate的注解/生成32位UUID
    @GeneratedValue(generator="idGenerator")
	@Column(name="order_id")
	private String orderId;

	@Column(name="buyer_address")
	private String buyerAddress;

	@Column(name="buyer_name")
	private String buyerName;

	@Column(name="buyer_openid")
	private String buyerOpenid;

	@Column(name="buyer_phone")
	private String buyerPhone;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="create_time")
	private Date createTime;

	@Column(name="order_amount")
	private BigDecimal orderAmount;

	@Column(name="order_status")
	private Integer orderStatus = OrderStatusEnum.NEW.getCode();

	@Column(name="pay_status")
	private Integer payStatus = PayStatusEnum.WAIT.getCode();

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="update_time")
	private Date updateTime;

	//bi-directional many-to-one association to OrderDetail
	@OneToMany(mappedBy="orderMaster")
	private List<OrderDetail> orderDetails;

	public OrderMaster() {
	}


	public List<OrderDetail> getOrderDetails() {
		return this.orderDetails;
	}

	public void setOrderDetails(List<OrderDetail> orderDetails) {
		this.orderDetails = orderDetails;
	}

	public OrderDetail addOrderDetail(OrderDetail orderDetail) {
		getOrderDetails().add(orderDetail);
		orderDetail.setOrderMaster(this);

		return orderDetail;
	}

	public OrderDetail removeOrderDetail(OrderDetail orderDetail) {
		getOrderDetails().remove(orderDetail);
		orderDetail.setOrderMaster(null);

		return orderDetail;
	}

}